#ifndef QDATACONNECTION_H
#define QDATACONNECTION_H

#include <QWidget>
#include <QTcpSocket>
#include <QUdpSocket>
#include "qextserialport.h"

enum connectionType{TCP,UDP,SERIAL};
enum baudRate{B4800,B9600,B19200,B57600,B115200};
enum connectionState{INACTIVE,CONNECTING,ACTIVE};

struct connectionInfo
{
  QString connName;
  connectionType connType;
  QString addr_port;
  quint16 port_baud;
  connectionState connState;
  quint8 connID;
};

class QDataConnection : public QWidget
{
  Q_OBJECT
public:
  QDataConnection(QWidget *parent = 0);
  QString getName();
  connectionType getType();
  QString getAddress_Port();
  quint16 getPort_Baud();
  connectionState getState();

  void setName(QString);
  void setType(connectionType);
  void setAddress_Port(QString);
  void setPort_Baud(quint16);
  void setID(quint16);

signals:
  void dataIn(connectionInfo, QByteArray);
  void serverDisconnect();
  void clientConnected();
  void connectionStatus(connectionState);

public slots:
  void dataConnect();
  void dataDisconnect();
  void dataOut(QByteArray);

private:
  QTcpSocket *tcpSocket;
  QUdpSocket *udpSocket;
  QextSerialPort *serialPort;
  connectionInfo connConfig;

private slots:
    void dataAvailable();
   void disconnected();
  void connectionChanged();
};

#endif // QDATACONNECTION_H
